package com.wallet.provider.controller;

import com.wallet.common.vo.PageResult;
import com.wallet.provider.model.Menu;
import com.wallet.provider.model.vo.TreeNodeVo;
import com.wallet.provider.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MenuController {

    @Autowired
    private MenuService menuService ;


    /**
     * 分页查询系统菜单
     * @param pageNum
     * @param pageSize
     * @param order
     * @param ordername
     * @return
     */
    public PageResult<Menu> getMenuList(int pageNum, int pageSize, String order, String ordername){
        return menuService.getMenuList(pageNum,pageSize,order,ordername);
    }

    /**
     * 获取菜单树
     * @return
     */
    public List<TreeNodeVo> getMenuTree(){
        return menuService.getMenuTree();
    }
    /**
     * 获取菜单树
     * @return
     */
    public List<TreeNodeVo> getMenuTree(Long roleId){
        return menuService.getMenuTree(roleId);
    }

    /**
     * 根据id查询菜单
     * @param id
     * @return
     */
    @RequestMapping(value = "/getMenuById", method = RequestMethod.GET)
    public Menu getMenuById(@RequestParam("id") Long id) {
        return menuService.getMenuById(id);
    }

    /**
     * 更新菜单
     * @param menu
     * @return
     */
    @RequestMapping(value = "/updateMenu", method = RequestMethod.POST)
    public boolean updateMenu(Menu menu){
        return menuService.updateMenu(menu);
    }

    /**
     * 删除菜单
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteMenu", method = RequestMethod.POST)
    public Boolean deleteMenu(@RequestParam("ids") Long[] ids){
        return menuService.deleteMenu(ids);
    }
}
